/**
 * 路由定义
 * 作者：夏冬琦 2021-08
 */


const routes = [

    //访问路由“/”,自动重定向到"/home"
    {
        path: '/',
        redirect: '/home'
    },   
    {
        path: '/home',
        name: 'Home',
        component: () => import('@/views/home.vue'),
        meta:{
            sub:false,
            navName:'主页'
        },
        redirect: '/report/charts',
        children:[
            //用户管理
            {
                path:'/security/user',
                name:'SecurityUser',
                component: () => import('@/views/security/user/index.vue'),
                meta:{
                    sub:true,
                    navName:'用户管理'
                }
            },
            //角色管理
            {
                path:'/security/role',
                name:'SecurityRole',
                component: () => import('@/views/security/role/index.vue'),
                meta:{
                    sub:true,
                    navName:'角色管理'
                }
            },

            //密码修改
            {
                path:'/security/password',
                name:'SecurityPassword',
                component: () => import('@/views/security/password/index.vue'),
                meta:{
                    sub:true,
                    navName:'密码修改'
                }
            },
            //基础信息
            {
                path:'/info/:info_type',
                name:'Info',
                component: () => import('@/views/info/index.vue'),
                meta:{
                    sub:true,
                    navName:(type)=>{
                        return {
                            customer:'客户信息',
                            standard:'规格信息',
                            color:'花色号信息'
                        }[type];
                        
                    }
                }
            },
            //计划维护
            {
                path:'/plan/manager',
                name:'PlanManager',
                component: () => import('@/views/plan/index.vue'),
                meta:{
                    sub:true,
                    navName:'计划维护'
                        
                    
                }
            },

            //坯布准备
            {
                path:'/process/rawcloth',
                name:'ProcessRawcloth',
                component: () => import('@/views/process/rawcloth/index.vue'),
                meta:{
                    sub:true,
                    navName:'坯布准备'
                        
                    
                }
            },

            //前处理 /process/pretreatment
            {
                path:'/process/pretreatment',
                name:'ProcessPretreatment',
                component: () => import('@/views/process/pretreatment/index.vue'),
                meta:{
                    sub:true,
                    navName:'前处理'                    
                }
            },

            //染色 /process/dye
            {
                path:'/process/dye',
                name:'ProcessDye',
                component: () => import('@/views/process/dye/index.vue'),
                meta:{
                    sub:true,
                    navName:'染色'                    
                }
            },

            //印花 /process/print
            {
                path:'/process/print',
                name:'ProcessPrint',
                component: () => import('@/views/process/print/index.vue'),
                meta:{
                    sub:true,
                    navName:'印花'                    
                }
            },

            //整理 /process/arrange
            {
                path:'/process/arrange',
                name:'ProcessArrange',
                component: () => import('@/views/process/arrange/index.vue'),
                meta:{
                    sub:true,
                    navName:'整理'                    
                }
            },

            //质检 /process/check
            {
                path:'/process/check',
                name:'ProcessCheck',
                component: () => import('@/views/process/check/index.vue'),
                meta:{
                    sub:true,
                    navName:'质量检验'                    
                }
            },

            //成品包装 /process/pkg
            {
                path:'/process/pkg',
                name:'ProcessPkg',
                component: () => import('@/views/process/pkg/index.vue'),
                meta:{
                    sub:true,
                    navName:'成品包装'                    
                }
            },

            //成品入库 /process/store
            {
                path:'/process/store',
                name:'ProcessStore',
                component: () => import('@/views/process/store/index.vue'),
                meta:{
                    sub:true,
                    navName:'成品入库'                    
                }
            },

            //成品出库 /process/out
            {
                path:'/process/out',
                name:'ProcessOut',
                component: () => import('@/views/process/out/index.vue'),
                meta:{
                    sub:true,
                    navName:'成品出库'                    
                }
            },

            //报表 /report/charts
            {
                path:'/report/charts',
                name:'ReportCharts',
                component: () => import('@/views/report/charts/index.vue'),
                meta:{
                    sub:true,
                    navName:'生产调度中心'              
                }
            },


        ]       
    },
    {
        path: '/login',
        name: "Login",
        component: () => import('@/views/login.vue')
    },
    
    

    {
        path: '/:pathMatch(.*)*',
        name: "NotFound",
        component: () => import('@/views/404.vue')
    },

 
    

];

// 判断路由是否存在
const existsRoute_inner = (path,theRoutes)=>{
    for (let i = 0; i < theRoutes.length; i++) {
        const r = theRoutes[i];
        if (r.path == path) {
            return true;
        }
        if (r.children && r.children.length) {
            const existsInChildren = existsRoute_inner(path,r.children);
            if(existsInChildren)return true;            
        }
    }
    return false;
};

export const existsRoute = (path) => {

    return existsRoute_inner(path,routes);

 
};

export default routes;